package org.smart4j.plugin.soap;

import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * @author djw
 * @time 2017/10/30 13:32
 */
public class SoapHelper {
    private static final List<Interceptor<? extends Message>> inInterceptorList=new ArrayList<>();
    private static final List<Interceptor<? extends Message>> outInterceptorList=new ArrayList<>();

    static {
        if(SoapConfig.isLog()){

        }
    }
    public static void publishService(String wsdl,Class<?>interfaceClass,Object implementInstance){
        ServerFactoryBean factory=new ServerFactoryBean();
        factory.setAddress(wsdl);
        factory.setServiceBean(implementInstance);
        factory.setInInterceptors(inInterceptorList);
        factory.setOutInterceptors(outInterceptorList);
        factory.create();
    }
    public static <T> T createClient(String wsdl,Class<? extends T> interfaceClass){
        ClientProxyFactoryBean factory=new ClientProxyFactoryBean();
        factory.setAddress(wsdl);
        factory.setServiceClass(interfaceClass);
        factory.setInInterceptors(inInterceptorList);
        factory.setOutInterceptors(outInterceptorList);
        return factory.create(interfaceClass);
    }
}
